Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the RNG splitting mechanism in Flax NNX by introducing a new Rngs.split method to replace the split argument in Rngs.fork and nnx.fork_rngs, which are now deprecated. A new prefix utility function is added to pytreelib for applying prefixes to pytrees based on filters, and the temp_flip_flag context manager is enhanced with a prefix argument for more flexible configuration. Review comments highlight a potential bug in the new Rngs.split method where RngStream objects might be unintentionally shared instead of being properly forked, and suggest strengthening a test case for fork_rngs to ensure correct restoration of RNG states.
2ab65b7 to
0a684c5
Compare
|
Interestingly, the following works: def my_fn(rngs):
model = Model(rngs)
return (model, rngs)
prefix = nnx.prefix(rngs, {'dropout': 0})
model, new_rngs = jax.vmap(my_fn, out_axes=(0, prefix), in_axes=(prefix,))(rngs)So why does As far as I can tell, this is because the |
|
Found a fix. The issue is that when we mask variables that haven't changed, we need the prefix for these positions to be None. So when constructing the prefix, we just need to ensure that we treat |
fd9674e to
99e12da
Compare
| return obj | ||
| return None | ||
|
|
||
| return jax.tree.map_with_path(lookup, pytree, |
There was a problem hiding this comment.
recently added nnx.map which can be used here, else you have to convert from the jax path format to the nnx path format
There was a problem hiding this comment.
This would require that the prefix filter only select Variable nodes. Which is probably what we usually want, but a little less flexible than using jax.tree.map_with_path as I have here.
There was a problem hiding this comment.
I get a strange error if I try to switch to nnx.map:
E At that key path, the prefix pytree vmap out_axes has a subtree of type
E <class 'flax.nnx.rnglib.RngKey'>
E but at the same key path the full pytree has a subtree of different type
E <class 'flax.nnx.extract.Mask'>.
What's nnx.extract.Mask? I guess I have some digging to do.
There was a problem hiding this comment.
For now, I'm just converting the jax path format to the nnx one, which makes the tests pass. But I'll investigate why nnx.map produces different behavior.
|
Added an additional test which is failing. Will debug. |
Followup to #5270. Adds
nnx.prefix, which can be used to provide 'in_axes' specifications based on a filters. Note that this depends on a separate PR for temporary configuration changes.